开发者

onsubmit Javascript popup to use value from submitted form syntax

I'm trying to make a little JScript popup that displays information from the form for confirmation. Here is what it looks like right now:

<input type="submit" value="Accept" onclick="return confirm('Press OK to confirm your purchase of' document.form.field.value)" />

The idea is to return a more useful conf开发者_开发技巧irmation than just 'Click OK to confirm' by showing values of the submitted form in the popup. Can anyone help me with the syntax?'


You can use the following:

<input type="submit" value="Accept" onclick="return confirm('Press OK to confirm your purchase of ' + document.getElementById('FIELDID').value)" />

Or you could modify the above to loop through each product and build a dynamic string with each product on a new line like this:

<input type="submit" value="Accept" onclick="return ConfirmOrder(); />


function ConfirmOrder()
{
 var msg = 'Click OK to confirm your order of\n';
 var prds = '';
 var prdElements = <GET PRODUCT ELEMENTS HERE>
 for (i=0; i<numPrds; i++)
 {
  prds = prdElements[i].value + '\n';
 }

 return confirm(msg + prds);
}

Also I think the onclick event should be in the onsubmit event of the form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜