Problem in assigning a particular value of submit using javascript

Arnab008

Broken In
<html>
<head>
<script language="javascript">
function check()
{
if (document.getElementById("t1")==1)
{
document.form.submit();
}
}
</script>
</head>
<body>
Enter a no <input type="text" id="t1"></input>
<input type="submit" name="sub" value="First"></input>
<input type="submit" name="sub" value="second"></input>
<input type="submit" name="sub" value="third"></input>
</body>
</html>



If I use document.form.submit(), which value will be taken? Specifically I want to take a particular value say first when the condition is satisfied. Please help me.
 

vickybat

I am the night...I am...
Check this approach. It uses drop downs using select tags and submits the appropriate value accordingly. In this case, submission is successful if value is "First".

PHP:
<!doctype html>
<html>
<head>
<script language="javascript">
function check(test)
{
if(test.value == "First")
{
alert("Success");
}else{
alert("Failed");
}
}
</script>
</head>
<body>
<form method = "POST" name = "myForm" id = "t1" onSubmit ="check(document.myForm.test);" >
<select name = "test" id = "testId" value = "test">
<option   value = "First">First</option>
<option   value = "second">second</option>
<option   value = "third">third</option>
</select>
<input type="submit" name = "submit" value="Submit"  />
</form>
</body>
</html>
 

avinandan012

Cyborg Agent
@op are you trying to achieve this :
when you click the button "First" text field should be populated with text "First"??


Code:
<html>
<head>
<script language="javascript">
function populateField(buttonId)
{
 document.getElementById('t1').value = document.getElementById(buttonId).value;
}
</script>
</head>
<body>
Enter a no <input type="text" id="t1"></input>
<input type="submit" name="sub" value="First" id="b1" onclick="populateField(this.id)"></input>
<input type="submit" name="sub" value="second" id="b2" onclick="populateField(this.id)"></input>
<input type="submit" name="sub" value="third" id="b3" onclick="populateField(this.id)"></input>
</body>
</html>
 
Last edited:
Top Bottom