简体   繁体   中英

How to POST textbox value using <a> tag?

my question might be little different but my requirement is something like that:

Here is the scenario...

I am having a page which POST all the values to next page on button click. Somthing like this...

    <form id="vrmainfrm" name="vrmainfrm" method="POST" action="nvendoraddcode.php">
     <input name="vrname" type="text" id="vrname" value=""/>
       ......
       ......
     <input type="submit" name="vrsubbmit" value="Submit"/>
    </form>

Now, I add a link beside vrname and I want to POST vrname's value to another page when I click on 'See Details' link.

I've tried something with AJAX from Google (I am not much aware about AJAX)...

<script>
function IsBlank_Post(){
    var x=document.forms["vrmainfrm"]["vrname"].value;
    if (x==null || x==""){
      alert("Company name must be filled out");
      return false;
    }
    else{
        $.ajax({
        term = $form.find( 'input[name="vrname"]' ).val()
        type: "POST",
        url: "nviewdetail.php",
        data: "{ vrname: term }",
        });
    }
}
</script>
    <form id="vrmainfrm" name="vrmainfrm" method="POST" action="nvendoraddcode.php">
     <input name="vrname" type="text" id="vrname" value=""/><a href="javascript:;" onclick="return IsBlank_Post();">See Details</a>
       ......
       ......
     <input type="submit" name="vrsubbmit" value="Submit"/>
    </form>

But it's not working! Can any one point out if I am doing in correct way or any other method is there? If yes please share.

Thanks in adv!

EDIT:

Hi guys,

I've done with my requirement by passing textbox value through query-string.

Here is code:

<script>
    function IsValue_Post(){
       var  vrname = document.vrmainfrm.vrname.value;
       window.location = "nviewdetail.php?cmpname=" + vrname;
      }
</script>

        <form id="vrmainfrm" name="vrmainfrm" method="POST" action="nvendoraddcode.php">
         <input name="vrname" type="text" id="vrname" value=""/><a href="javascript:IsValue_Post();">See Details</a>
           ......
           ......
         <input type="submit" name="vrsubbmit" value="Submit"/>
        </form>

And on nviewdetail.php:

$searchname=$_REQUEST['cmpname'];

As simple as that...Thanks all for your support!

you have an error in ajax function..var term should be outside the ajax call. data should be object and not string

try this

  ...
  else{
   var term = $form.find( 'input[name="vrname"]' ).val();  //<---here declare it outside the ajax
    //or  
  var term =$("#vrname").val(); //<--not sure what $form is but i think this should work
   $.ajax({
    type: "POST",
    url: "nviewdetail.php",
    data: { vrname: term }, //<--here this should be object
     success:function(data){  //<--- callback function which is called whn ajax call succeed
         //do your stuff
     }
    });
  }

Use below code for ajax:

function IsBlank_Post(){
    var x = $("#vrname").val();
    if (x==null || x==""){
      alert("Company name must be filled out");
      return false;
    } else {
        $.ajax({
        type: "POST",
        url: "nviewdetail.php",
        data: {'vrname': x},
        success: function(returnData){
            alert("Successfull");
            return true;
        }
        });
    }
}

And at the page nviewdetail.php you can get it by

$vrname = $_REQUEST['vename'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM