Solved

JavaScript - get value of input field

Posted on 2014-11-10
4
207 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
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 6

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now