Click to See Complete Forum and Search --> : Passing var to javascript
aisyah
10-07-2003, 04:04 AM
I have submit button - Add and Delete.
I want to pass variable to javascript as brelow :-
<input type submit name=add onclick="skip=true&first=true">
this two variables than will do something in javascript.
<script language="javascipt">
var skip = false;
if (skip) return true;
</script>
But i get syntax error when trying to pass 2 variables using onclick command
thanks
Khalid Ali
10-07-2003, 09:46 AM
<input type submit name=add onclick="skip=true;first=true">
& is not the operator used in this case,you want to separate multiple statements using ;
a better aproach(INMO) will be to set variable values using a function
<input type submit name=add onclick="setVals(true,true);">
and in javascript
<script type="text/javascript">
var skip=false;
var first = false;
function setVals(flag1,flag2){
skip = flag1;
first = flag2;
}
//now you can use them as you wish
aisyah
10-07-2003, 10:14 PM
Originally posted by Khalid Ali
<input type submit name=add onclick="skip=true;first=true">
& is not the operator used in this case,you want to separate multiple statements using ;
a better aproach(INMO) will be to set variable values using a function
<input type submit name=add onclick="setVals(true,true);">
and in javascript
<script type="text/javascript">
var skip=false;
var first = false;
function setVals(flag1,flag2){
skip = flag1;
first = flag2;
}
//now you can use them as you wish
Thanks Khalid...
Works as you mentioned ...
I just want to asked if i have a form
<form action="display.jsp" method="post" onsubmit="return validate();">
my questions :
Suppose 1 have two submit button
one is "Add Item" and the other one is "Add Data".
How i want to check the button value that only when button "Add Data" is click , we do the validate function in javascript.?
Khalid Ali
10-08-2003, 12:21 AM
take a look at your form element
<form action="display.jsp" method="post" onsubmit="return validate();">
see the text in bold,this event has to be trigered by soe other event or action.
in the rest of the form code you will have a
input type="submit"
this will trigger that onsubmit event,
on theother hadnif you have simple button
<input type="button" onclick="addItem()"/>
clicking on this button will not send the form..
aisyah
10-08-2003, 04:20 AM
Originally posted by Khalid Ali
take a look at your form element
<form action="display.jsp" method="post" onsubmit="return validate();">
see the text in bold,this event has to be trigered by soe other event or action.
in the rest of the form code you will have a
input type="submit"
this will trigger that onsubmit event,
on theother hadnif you have simple button
<input type="button" onclick="addItem()"/>
clicking on this button will not send the form..
Thankg for the reply.
Just wanr to know how can i know whether this is the first time i click on the add button?
If this is the first tme, no checking will be done else do checking
thanks