Reputation: 77
I'm having trouble getting the value of a custom prompt in PHP. I actually made a custom prompt that consist of two input boxes and stored it in a variable. When I clicked a button I'll just call it. I have no problem with this for its working well.
var popup = "div id='overlay'>
<div id='box_frame'>
<div id='box'><a href='javascript:closeDialog()'>close</a>
<h2>Edit Material</h2>
<h1>"+projName+"</h1>
<label>Material</label>
<input name='boxMatName' type='textbox' value='"+matName+"' disabled />
<br>
<label>Quantity</label>
<input id='boxEstVal' type='textbox' value='"+estQty+"' />
<br>
<button onclick='javascript:saveDesc()'>Save</button>
<div id='try'></div>
</div>
</div>
</div>
";
I tried this to get the value from the prompts:
function saveDesc(){
var mat = ('#boxMatName').val();
var est = ('#boxMatName').text();
alert(mat+est);
However, I am not getting any results. Can you help me understand what I am doing wrong?
Upvotes: 1
Views: 162
Reputation: 37876
why dont you give another id to your input:
var popup = "div id='overlay'>
<div id='box_frame'>
<div id='box'><a href='javascript:closeDialog()'>close</a>
<h2>Edit Material</h2>
<h1>"+projName+"</h1>
<label>Material</label>
<input name='boxMatName' id="boxMatName" type='textbox' value='"+matName+"' disabled />
<br>
<label>Quantity</label>
<input id='boxEstVal' type='textbox' value='"+estQty+"' />
<br>
<button onclick='javascript:saveDesc()'>Save</button>
<div id='try'></div>
</div>
</div>
</div>
then, this should work.
function saveDesc(){
var mat = $('#boxMatName').val();
var est = $('#boxEstVal').val();
alert(mat + ' - ' + est);
}
by the way, did you include the jquery in the head of your html file?
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
Upvotes: 1
Reputation: 34895
You are using <input>
so you need val()
and not text()
:
var mat = $("input[name=boxMatName]").val();
var est = document.getElementById('boxEstVal').value; // or $('#boxEstVal').val();
Upvotes: 1