Yii Framework Forum: Run Javascript before Submit - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Run Javascript before Submit

#1 User is offline   nadji25023 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 14-June 12

Posted 07 July 2012 - 08:06 AM

Assalemou 3alaykom,


I'm newbie in Yii && PHP/Javascript. I want to run a Javascript function before submit my Form

Do some thing like that in Yii

<html>
<head>
<script>
function doThis()
{
alert("testing");
return true
}
</script>
</head>
<body>
<form action="test.php" onsubmit="return doThis()" method="post">
<input type=submit >
</form>
</body>
</html>


Any body can help me how to implement that in Yii ?

Many thanks ya ikhwan :D
0

#2 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,180
  • Joined: 05-January 12
  • Location:Morocco

Posted 12 July 2012 - 02:11 PM

Wa 3alaykum assalam wa arra7ma

A good example lays in the "admin.php" view that is automatically generated by gii/giix:

<?php Yii::app()->clientScript->registerScript('someScript', "
$('#testForm').submit(function() {
    alert("testing");
});
");
?>

<form id="testForm" action="test.php" method="post">
    <input type=submit >
</form>

0

#3 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 24 July 2012 - 01:04 PM

Do it like this:
<html>
<head>
<script>
$("#myform").submit(function(event){
event.preventDefault();
doThis();
$("#myform").submit();
});
function doThis()
{
alert("testing");
return true
}
</script>
</head>
<body>
<form id="myform" action="test.php" method="post">
<input type=submit >
</form>
</body>
</html>

0

#4 Guest_Eduardobync_*

  • Group: Guests

Posted 11 March 2015 - 10:45 PM

Someone run javascript code faster like c code, exist some tool or API to make faster javascript code.
For large operationsfor example, big matrix multiplications I use webworkers and my script is stable, but its run slow.
0

#5 User is offline   Abed Alzain 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 124
  • Joined: 22-April 12
  • Location:Gaza, Palestine

Posted 16 March 2015 - 03:07 AM

Hi, try this code:

$('#form').on('beforeSubmit', function(e) {
   //your code
  return false;
}).on('submit', function(e){
    e.preventDefault();
});

W: http://pph.me/abed
Skype: abed.m.alzain
0

#6 User is offline   Muaid 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 25-October 10
  • Location:Saudi Arabia

Posted 27 March 2015 - 10:05 AM


السلام عليكم،، بعض الاخوان لايجيد تحدث الانجليزية وقد تم تخصيص هذا المنتدي للمتحدثين باللغة العربية فالافضل لو نساعدهم ونشركم معنا في المنتدي لتتحقق الفائدة من هذا المنتدي العربي

لكم اجمل التحايا والشكر على اطروحاتكم ومشاركاتكم


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users