Solved

JavaScript - get value of input field

Posted on 2014-11-10
4
213 Views
Last Modified: 2014-11-10
HI,
just wondering if there is a simple way to get the value of my tracking_number input field to pass to another input button?

Thanks

<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
<input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35">

<input type="button" onClick="if(confirm('This will send an email to the customer with their Delivery Tracking Number.')){location.href='view_upd_order.php?order_id=123&send_tracking=Y&tracking_number=?????'}" value="Send Tracking Details">

</div>

Open in new window

0
Comment
Question by:sabecs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40434238
<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
   <input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35" />
   <input type="button" onclick="doSomething();" value="Send Tracking Details" />
</div>
<script>
    var doSomething = function() {
        var answer = confirm('This will send an email to the customer with their Delivery Tracking Number.');
        if(answer==true) {
             var tn_value = document.getElementById("tracking_number").value;
             location.href = 'view_upd_order.php?order_id=123&send_tracking=Y&tracking_number=' + tn_value;
        }
    }
</script>

Open in new window

0
 
LVL 7

Expert Comment

by:cstsang
ID: 40434243
Try the following:
<script language=javascript>
function check()
{
    var field=document.getElementById("tracking_number");
    if(confirm('This will send an email to the customer with their Delivery Tracking Number.'))
    {
        location.href='view_upd_order.php?order_id=123&send_tracking=Y&tracking_number='+field.value; 
    }
}
</script>
<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
<input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35">

<input type="button" onclick="check()" value="Send Tracking Details">

Open in new window

0
 
LVL 9

Expert Comment

by:Mukesh Yadav
ID: 40434289
You just need to replace ?????' with '+ document.getElementById('tracking_number').value

Remaining you have already done.
0
 
LVL 5

Expert Comment

by:Ronak Patel
ID: 40434319
basically its the same as above solutions.. I've just added a validation block.. which will check the tracking number value.. If you have a specific format of your tracking number.. you can validate it by performing RegEx validation..

<script type="text/javascript">

function SendTrackingDetails(obj)
{
	if(confirm('This will send an email to the customer with their Delivery Tracking Number.'))
	{
		if(obj.value != undefined && obj.value != "") //Check if Tracking Number is entered or not..
		{
			location.href='view_upd_order.php?order_id=123&send_tracking=Y&tracking_number=' + obj.value;
		}
		else
		{
			alert('Enter Tracking Number.');
			return false;
		}
	}
}

</script>

<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
<input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35" />

<input type="button" onClick="return SendTrackingDetails(document.getElementById('tracking_number'));" value="Send Tracking Details" />

</div>

Open in new window

0

Featured Post

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question