fariezza
fariezza

Reputation: 3

How to put value/parameter in javascript

The situation:

User can add an application (channel) that they want. So when user adds an application, one prompt will ask user confirm to add application (*with name of application and ID) or not?

The problem is i don't know how to call/put that value in javascript. hope anyone can help me as well :)

Here code I'm using:

Application ID: <input type="text" class="txt" name="widget_id" value="" size="30" /> 
<INPUT TYPE="hidden" NAME="box_id" value='<?=$user_box_id;?>'>
<INPUT TYPE="hidden" NAME="user_name" value='<?=decode($user_name);?>'>

<input type="submit" class="btn" name="addapp" value="Add Apps"  onClick="javascript:if(confirm('Are You Sure To Add This Apps? ')) location='<?php echo site_url("$url/box/add_User_App/".$Add_apps['box_id']."/".$Add_apps['user_name']."/".encode($Add_apps["widget_id"]) )?>'"></a></td>

Upvotes: 0

Views: 154

Answers (1)

Diode
Diode

Reputation: 25155

You can use the onsubmit event of form to do this

<form action="<?php echo site_url("$url/box/add_User_App/".$Add_apps['box_id']."/".$Add_apps['user_name']."/".encode($Add_apps["widget_id"]) )?>" onsubmit="confirmation(event);">
    <input type="text" name="appname" id="appName"/>
    <input type="text" name="appid" id="appID"/>
    <input type="submit" value="go"/>         
</form>

<script type="text/javascript" >
   function confirmation(e){
      var appName = document.getElementById("appName");
      var appID = document.getElementById("appID");
      if(!confirm('Are You Sure To Add This Apps with App Name : ' + appName.value + " and App ID : " + appID.value + " ?")){
          e.preventDefault();
          return false;        
      }
   }
</script>

sample : http://jsfiddle.net/diode/5YZh8/2/

Upvotes: 1

Related Questions