Mark Lee
asked on
javascript form alert
<form>
<ntb:Combo id="myCombo" Mode="classic" >
<ntb:ComboTextBox
Width="300px" value="Keyword Search - Then Press Down Arrow"
DataFieldIndex=1>
</ntb:ComboTextBox>
....................etc etc
</ntb:Combo>
<input type="submit" value="Add Item" >
<form>
the documentation states that the Combo Object can be accessed by the following
myComboObject= document.getElementById("m yCombo").o bject;
what I need is a javascript function that will give an alert
"Please Select An Item"
if the form is submitted and the value "Keyword Search - Then Press Down Arrow" is in the ComboTextBox field
in other words to stop some confusion when a new user simply clicks on the submit button before realising that they have not selected a search item first
<ntb:Combo id="myCombo" Mode="classic" >
<ntb:ComboTextBox
Width="300px" value="Keyword Search - Then Press Down Arrow"
DataFieldIndex=1>
</ntb:ComboTextBox>
....................etc etc
</ntb:Combo>
<input type="submit" value="Add Item" >
<form>
the documentation states that the Combo Object can be accessed by the following
myComboObject= document.getElementById("m
what I need is a javascript function that will give an alert
"Please Select An Item"
if the form is submitted and the value "Keyword Search - Then Press Down Arrow" is in the ComboTextBox field
in other words to stop some confusion when a new user simply clicks on the submit button before realising that they have not selected a search item first
Yeah, I guess it is jsObject. I was going by your earlier comment using ".object". not sure what the difference is.
ASKER
the script works to produce the alert but then appears to want to submit the form still, the work around uses the document.location = history.go(0);
is there another way to get the script to just close the alert box, the return false does not appear to work in this case
<script>
function checkSubmit(){
var myComboObject= document.getElementById("m yCombo").o bject;
if(myComboObject.GetTextVa lue() == "Keyword Search - Then Press Down Arrow"){
alert("Please Select An Item");
document.location = history.go(0);
return false;
}
return true;
}
</script>
is there another way to get the script to just close the alert box, the return false does not appear to work in this case
<script>
function checkSubmit(){
var myComboObject= document.getElementById("m
if(myComboObject.GetTextVa
alert("Please Select An Item");
document.location = history.go(0);
return false;
}
return true;
}
</script>
try changing the onsubmit to the following:
onsubmit="return checkSubmit()"
onsubmit="return checkSubmit()"
This is not valid JS
document.location = history.go(0);
document.location = history.go(0);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<script>
function checkSubmit(){
var myComboObject= document.getElementById("m
if(myComboObject.GetTextVa
alert("Please Select An Item");
return false;
}
return true;
}
</script>
then at your form:
<form ... onsubmit="checkSubmit();">
<ntb:Combo id="myCombo" Mode="classic" >
<ntb:ComboTextBox
Width="300px" value="Keyword Search - Then Press Down Arrow"
DataFieldIndex=1>
</ntb:ComboTextBox>
....................etc etc
</ntb:Combo>
<input type="submit" value="Add Item" >
</form>