0

I've got a form which posts its results using "get" method. I was wondering how I could add some additional values to these results before they are submitted.

What I did so far is overload the submit function so I could concat my additional string which I wish to pass along with the form results to the destination url.

On regular submit the destination url gets the results as follows:

   ..dest url?txtName=e&txtAge=r&gender=mail&select=1

What I am attempting to do is append another string to these results

  ..dest url?txtName=e&txtAge=r&gender=mail&select=1|myStringResult

I've overloaded the submit

    function overLoadSubmit() 
    {
        window.addEventListener('submit', newSubmit, true);
        HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;
        HTMLFormElement.prototype.submit = newSubmit;
    }

The original submit is called after newSubmit(), and that's where I would like to append my string.

    function newSubmit()
    {           
        var myForm = document.forms[0];
        var s = "|myStringResult";             
        // here is where i would like to append s ,
        // but i can't figure out how to reference the form results  
        // or how to add it to the original submit
    }

I've also tried adding an hidden input control

    <input type="hidden" id="_body" value="getValues();"/>

since myResultString is really long and is in fact an entire html document

    function getValues() 
    {
        var _doc = document.childNodes[1].innerHTML;
        return '|' + _doc; 
    }

This doesn't seem to work.

1
  • While it is tempting to do so, you should never augment host objects or assume that browsers implement prototype inheritance. kangax, What’s wrong with extending the DOM Commented Aug 3, 2011 at 5:00

1 Answer 1

3

Why not add a hidden field to the form instead?

<input type="hidden" name="myhiddenfield" value="myStringResult">

The value will get appended to the URL when the form is submitted.

Sign up to request clarification or add additional context in comments.

2 Comments

o'k i got it to work i replaced id with name i'm new to javascript :) , its really annoying thanks Gauarv .
I've never tried that, but likely you should use encodeURLComponent on the string before assigning it to the input's value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.