JavaScript html two input values get swapped html input values,html input values array,html input value

I'm trying to send a http request to a website and I need the user to fill out their names and mobile number. I'm trying to do it as followed (I'm still working on the validate function so right now it always return false. )

<html> <meta charset="UTF-8" />

<script type="text/javascript">

    function validate(){
        var a = document.forms["sendform"]["mobile"].value;
        alert(a);

        return false;
    }

</script>

/*<style>

.myButton {
    background-color:#4a45c7;
    -moz-border-radius:28px;
    -webkit-border-radius:28px;
    border-radius:28px;
    border:1px solid #193eab;
    display:inline-block;
    cursor:pointer;
    color:#ffffff;
    font-family:Arial;
    font-size:17px;
    padding:16px 31px;
    text-decoration:none;
    text-shadow:0px 1px 0px #282b66;
    position: absolute;
    top: 50%;
    left: 45%;
}

.userNameField{
    position: absolute;
    top: 45%;
    left: 45%;
}

.userEmailField{
    position: absolute;
    top: 40%;
    left: 45%;
}

.userMobileField{
    position: absolute;
    top: 35%;
    left: 45%;
}

.userName{
    position: absolute;
    top: 32.5%;
    left: 38%;
}

.userEmail{
    position: absolute;
    top: 37.5%;
    left: 38%;
}

.userMobile{
    position: absolute;
    top: 42.5%;
    left: 38%;
}*/

</style>

    <body>
        <?php

        $stcate = $_POST["stCate"];
        $stcode = $_POST["stCode"];
        $result = $stcate . $stcode;
        ?><br> 
            <form name="sendform" id = "sendform" method="post" action="https://www.ezship.com.tw/emap/ezship_request_order_api.jsp" onsubmit="return validate();">


            <p class = "userName"> 取件人姓名 </p>
            <input type="text" name="rv_name" id = "name" class = "userNameField"/> <br>

            <p class = "userMobile"> 取件人電話</p>
            <input type="text" name="rv_mobile" id = "mobile" class = "userMobileField"/> <br>


            <input type="hidden" name="st_code" value= "<?php echo $result;?>"/>
            <input type="hidden" name="rv_addr" value="" />
            <input type="hidden" name="rv_zip" value="" />
            <input type="hidden" name="rtn_url" value='http://localhost/orderstatus.php' />
            <input type="hidden" name="web_para" value='yes' />

            <input type="submit" class = "myButton" value='確認寄出' />

        </form>


    </body>
</html>

After I entered some values for both inputs and hit send, the alert always prints out the value for input "name" even though I'm trying to print out input "mobile". The same thing happens when I try to print out value for "name", it just prints out value for "name". I don't understand why the values are swapped? I tried it without any PHP code and CSS and it works the way I expect. What am I doing wrong?

Answer:1

You don't have a head tag. That may be the problem with it's running correctly without style tags and php code. Try adding the head tag.

Answer:2

Since the attribute mobile that you're using is an id, so you can use document.getElementById("sendform").value like this:

function validate(){
    var a = document.getElementById("sendform").value;
    alert(a);
    return false;
}
Answer:3

I have a few divs that share the same class. I have a dropdown that changes the background color of one of those divs when selected(option 2 changes div #2). My question is how can I change the ...

I have a few divs that share the same class. I have a dropdown that changes the background color of one of those divs when selected(option 2 changes div #2). My question is how can I change the ...

  1. find which element has focus
  2. find which element is scrolling
  3. find which element is clicked jquery
  4. find which element python
  5. find out which element you are
  6. jquery find which element is focused
  7. jquery find which element is visible
  8. find element in list python
  9. find_element_by_xpath
  10. find element in array javascript
  11. find element in vector c++
  12. find_element_by_css_selector
  13. find_element_by_class_name
  14. find element by xpath selenium python
  15. find element by class
  16. find element in array python
  17. find_element_by_id
  18. find_element_by_link_text
  19. find element jquery
  20. find element by class selenium

I am currently creating a webpage using HTML/CSS and jQuery/Basic JS. I'm using a jQuery code to show a GIF image while the website is loading $(window).load(function() { $(".loading").fadeOut(...

I am currently creating a webpage using HTML/CSS and jQuery/Basic JS. I'm using a jQuery code to show a GIF image while the website is loading $(window).load(function() { $(".loading").fadeOut(...

  1. website loading page design
  2. website loading page
  3. website page loading speed test
  4. website page loading speed
  5. website page loading animation
  6. website page loading time
  7. website page loading test
  8. website page loading slow
  9. website loading blank page
  10. create website loading page
  11. website stuck loading page
  12. website not loading blank page

I have a basic bootstrap modal to log in, which doesn't close itself when I hit submit. I solved it using this simple jquery: $('#myModal').modal('hide'); But I also want the modal to fade out ...

I have a basic bootstrap modal to log in, which doesn't close itself when I hit submit. I solved it using this simple jquery: $('#myModal').modal('hide'); But I also want the modal to fade out ...

  1. hide bootstrap modal jquery
  2. hide bootstrap modal using javascript
  3. hide bootstrap modal after 3 seconds
  4. hide bootstrap modal on page load
  5. hide bootstrap modal angular
  6. hide bootstrap modal on button click
  7. hide bootstrap modal using jquery
  8. hide bootstrap modal popup using jquery
  9. hide bootstrap modal
  10. hide bootstrap modal on ajax success
  11. hide bootstrap modal on click
  12. hide bootstrap modal backdrop
  13. hide bootstrap modal js
  14. hide bootstrap modal in angular 4
  15. hide bootstrap modal from code behind c#
  16. hide bootstrap modal after submit
  17. hide bootstrap modal react
  18. hide bootstrap modal in c#
  19. hide bootstrap modal event
  20. hide bootstrap modal angularjs

How to convert string to timestamp and date in JS. here am using Date.parse(), but its not working in IE and FF. My code is.. in chrome its working fine. var str = "05-Sep-2013 01:05:15 PM "; ...

How to convert string to timestamp and date in JS. here am using Date.parse(), but its not working in IE and FF. My code is.. in chrome its working fine. var str = "05-Sep-2013 01:05:15 PM "; ...

  1. date.parse not working in ie
  2. date.parse not working in safari
  3. date.parse not working
  4. date.parse not working in ie11
  5. date.parse not working in firefox
  6. date.parse not working in mozilla
  7. date.parse not working in chrome
  8. date.parse not working in internet explorer
  9. date.parse not working jquery
  10. date.parse not working java
  11. date.parse javascript not working
  12. tableau date parse not working
  13. date.parse in javascript not working in ie
  14. javascript date.parse not working in firefox