Forum Moderators: open
<form action="someurl">
<input type=hidden name=guns value=butter>
<input type=submit name=submit value="Search">
<input type=submit name=advanced value="Advanced">
</form>
What I'd like to see happen is that clicking "Search" will work normal and clicking "Advanced" will cause the
<input type=hidden name=guns value=butter>
line to disappear i.e. not get sent to the result page.
Is this possible?
It would be nice if this could work but I bet it's not valid
<form action="someurl">
<input type=submit name=submit value="Search">
<form action="someurl">
<input type=submit name=advanced value="Advanced">
</form>
<input type=hidden name=guns value=butter>
</form>
<script type="text/javascript">
function testRemove(name)
{
var elm = document.forms[0].elements[name];
elm.parentNode.removeChild(elm);
}
</script>
</head>
<body>
<!- Changed names of submit buttons.
Not good to have an element named, "submit" -->
<form action="x.htm" method="get">
<input type=hidden name=guns value=butter>
<input type=submit name=subSearch value="Search" onclick="testRemove('guns')">
<input type=submit name=subAdvanced value="Advanced">
</form>
</body>
I meant that the advanced submit should remove the hidden input. I'm assuming I need to switch the function call to the advanced, correct?
Also, is there no way to do this inline without a function in the header (since I use templates and mix and match headers, that function complicates matters for my implementation). It would have been perfect if I could make the hidden value part of the submit. Something like
<input type="submit" name="guns" value="butter" textonthesubmitbutton="Submit">
<input type="submit" name="advancedsubmit" value="Advanced">
But unfortunately there is no such thing as a "textonthesubmitbutton" :)
But maybe there is an inline javascript to change only the value of the Submit when clicked (without the text appearing on the button)?
Hopefully my question is clear?
<input type="submit" name="advancedsubmit" value="Advanced"
onclick="var e=this.form.elements.guns;e.parentNode.removeChild(e);">
Would it not be easier to simply set the value of "guns" to ""?
Then detect that on the receiving end.
onclick="this.form.elements.guns.value=''" ..or remove the name attribute, so that the field isn't submitted at all:
onclick="this.form.elements.guns.removeAttribute('name')" If your form has a text field, then it will be possible, and very likely, that the user will submit by pressing <return>. Neither submit button will be clicked. What is the default state of "guns" in this case?
Thanks for the help! One day I will master javascript.
I hope...