JavaScript Form Variable Passing javascript form variable passing

I am using Javascript to pass form variables to the PHP page sprcial_action.php but it is not redirecting to that page. My code is given below, please tell me where is the problem?

<script>
function formSubmit(index)
{
    var image = document.getElementById("hdnimage" + index);
    var email = document.getElementById("email" + index);

    window.location.href = "sprcial_action.php?name=" + image; 
}
</script>

<form enctype="multipart/form-data" id="form1" name="form1" method="get">

<div class="offers">

    <div class="offer-banner">
         <img src="/images/specialoffer/offer-1.png" />
    </div>
    <div class="mobile">
         <input type="text" value="Mobile" name="mobile" />
    </div>
    <div class="or-button"></div>
    <div class="email">
         <input type="text" value="Email Address" name="email" id="email0"  />
    </div>
    <input type="hidden" name="hdnimage0" id="hdnimage0" value="/images/specialoffer/offer-1.png" />
    <div class="redem-copon">
         <!--<a target='_blank' href="#"><img src="/images/specialoffer/copun.png" /></a>-->
         <input type="image" src="/images/specialoffer/copun.png" onclick="formSubmit(0)" />
    </div>
</div>
</form>
Answer:1

window.location.href needs full path starting with http://. and add .value to image object

you should be writing as

window.location.href = "http://mydomain.com/sprcial_action.php?name=" + image.value;
Answer:2

Your image variable refers to the input object, not its value. To get its value, add .value:

window.location.href = "sprcial_action.php?name=" + image.value;
// here -------------------------------------------------^

But note that you're getting the email field but not then doing anything with it, and setting the href does not submit a form, it just takes you to the given page.

If you want to change the location the form submits to, you have to set the action property on the form object (and not change location.href):

var form = document.getElementById("form1");
form.action = image.value;

I'm not 100% certain you can change that during a form submit reliably across browsers, you'll need to test on your target browsers.

Answer:3

I want to get the password from the user by means of a prompt box and if the entered password is invalid show an error message in a label which is inside the promptbox I mentioned.I s it possible or ...

I want to get the password from the user by means of a prompt box and if the entered password is invalid show an error message in a label which is inside the promptbox I mentioned.I s it possible or ...

Will the following log itself upon getting clicked in every browser? <a href="#" onclick="console.log(this);">Click me!</a>

Will the following log itself upon getting clicked in every browser? <a href="#" onclick="console.log(this);">Click me!</a>

  1. does reliably mean

I'm making a extension for Google Chrome, the extension deletes all browsing data when the user clicks it, the extension works fine but now im trying to add a options panel where the user can choose ...

I'm making a extension for Google Chrome, the extension deletes all browsing data when the user clicks it, the extension works fine but now im trying to add a options panel where the user can choose ...

  1. save data localstorage
  2. save data in localstorage javascript
  3. save data in localstorage c#
  4. save data in localstorage jquery
  5. save data in localstorage react
  6. save form data localstorage
  7. save data to localstorage js
  8. save data in localstorage angular 2
  9. save data to localstorage react native
  10. save data in localstorage angular
  11. save data in localstorage angularjs
  12. save data in localstorage angular 6
  13. save data in localstorage angular 5

I have a forum, and on every persons post theres a button that allows a moderator to mute someone after reviewing the post/entering hours to mute for in a window using simplemodal. In the code that ...

I have a forum, and on every persons post theres a button that allows a moderator to mute someone after reviewing the post/entering hours to mute for in a window using simplemodal. In the code that ...

  1. separate html from php
  2. separate html from css
  3. separate html from javascript
  4. separate html from js
  5. separate html from files
  6. react separate html from js
  7. reactjs separate html from js
  8. php separate html from code
  9. separate in html
  10. separate script from html
  11. separate jquery from html
  12. html separate image from text
  13. html separate content from structure
  14. html separate navigation from content
  15. separate header from html
  16. separate php file from html
  17. separate inline css from html
  18. separate js file from html
  19. separate css file from html