Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm currently creating a form that is very similar to the following code.

<form name="test" action="/go/test" method="post">
  <input type=hidden name="hotspot_url" value="http://www.test.com/">
  <input name="cky" value="<%write(cky);%>" type="hidden">
  <input name="accept" value="Accept" type="hidden">
  <input name="saccept" size="20" value="I Accept" onClick="hotspot.accept.value='Accept'" type="submit">
  <input name="sdisconnect" size="20" value="I Decline" onClick="hotspot.accept.value='Decline'" type="submit">
</form>

However, the new form has a text input field. What I want to achieve is that the value entered in that text field is placed, upon send, after the test.com value (location marked with xxx)

<input type=hidden name="hotspot_url" value="http://www.test.com/xxx">

I've looked around - but i can't seem to find a solution. What would be the best way to get this done?

share|improve this question

2 Answers

up vote 0 down vote accepted

You can use a buttons onclick event, which is not of type submit. When onclick occurs, you can first change the value of hidden field and then submit the form.

Or if you use JQuery, you can use the following jQuery code to do something before the form is submitted:

$(function() {
    $('#form').submit(function() {
        // DO STUFF
        return true; // return false to cancel form action
    });
});
share|improve this answer
I knew would be something simple. thanks for the quick reply! – Jan yesterday

You can give both inputs an id, and do something like this:

give the form an "onsumbit= doThis()"

function doThis(){

 var hiddeninput= $('#hiddeninput').val();
 var input = $('#input').val();
 $('#hiddeninput').val(hiddeninput+input);

 return true; 
}

this is very simple nothing fancy.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.