I have a code like
<SCRIPT LANGUAGE="JavaScript">
setTimeout('document.test.submit()',1000);
</SCRIPT>
I follow the tutorials on how to do a settimeout function but it is not working with my php code.. my Whole code looks like this..
<head>
<link rel="stylesheet" type="text/css" href="css.css" />
<SCRIPT LANGUAGE="JavaScript">
setTimeout('document.test.submit()',1000);
</SCRIPT>
</head>
and my php looks like this..
echo "<form name=\"asd\" id=\"form1\" action=\"PostTest1.php\" method=\"post\" >";
echo "<tr><td>";
echo $row['Description'] . "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"A\"> A.)" . $row['Ans1'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"B\"> B.)" . $row['Ans2'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"C\"> C.)" . $row['Ans3'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"D\"> D.)" . $row['Ans4'];
echo "<br>";
echo "<input type=\"submit\" value=\"submit\" name=\"submit\">";
echo "</td></tr>";
echo "</form>";
My button is not auto clicking.. Thank you for the advance help.. :)
(Sorry for my grammar)
Try this:
setTimeout(document.getElementById("form1").submit(),1000); alternatively, you could also do this: setTimeout(document.asd.submit(),1000); since you've named your form.
You need to find the correct element to submit, document.test is not valid in your supplied scenario.
EDIT: You need to remove the name attribute from your submit button as when you call .submit() it is finding that element, rather than submitting the form like you'd expect.
Fiddle: http://jsfiddle.net/KyleMuir/yKG3U/
setTimeout needs a function to call and the timeout.
you can do:
setTimeout(my_func(), 1000);
function my_func(){
document.getElementById("id_form").submit();
}
That way should work.
Related
I want to insert the following code in the message part of a php mail().
"<input type='text' id='current_user_first_name'
name='current_user_first_name' value='<?php echo
$current_user_firstname; ?>'>"
\ The full message will look like the following.
$to="$managers_email";
$subject="REQUEST FOR APPROVAL";
$message=
"<html>
<head>
<title>REQUEST FOR TIME SHEET APPROVAL</title>
<style>
</style>
</head>
<body>
<form>
<input type='text' id='current_user_first_name'
name='current_user_first_name' value='<?php echo
$current_user_firstname; ?>'>
<input type='submit' value='APPROVED'
formaction='http://telecomsolutions.com/approved.php'>
<input type='submit' value='DRAFT REJECT'>
<textarea name='reject_reason' placeholder='Enter reject
reason'
id='reject_reason' rows='15' cols='30'>
<input type='submit' value='REJECT'
formaction='http://telecomsolutions.com/reject.php'>
</form>
</body>
</html>";
$headers="MIME-Version: 1.0" ."\r\n";
$headers.="Content-type:text/html;charset=UTF-8"."\r\n";
$headers.='from:<$current_user_email>'."\r\n";
mail($to,$subject,$message,$headers);
echo "Your request submitted successfully"
?>
Each time a client submits a request for approval the details of the client will be fetched from the database, used in place of the variables in the html code and sent to the Manager for approval.
Please can this work and if not,any other way to make it work?
$variable = "John Doe";
$message = "Hi " . $variable . " , How are you?";
The above will result in
Hi John Dow , How are you?
You won't do like this
$variable = "John Doe";
$message = "Hi <?php echo $variable ?> , How are you?";
The first mistake you are doing is using <?php again inside your PHP file.
Then the second mistake is to use echo inside your above mentioned <php
Correct $message will be
$message=
"<html>
<head>
<title>REQUEST FOR TIME SHEET APPROVAL</title>
<style>
</style>
</head>
<body>
<form>
<input type='text' id='current_user_first_name' name='current_user_first_name' value='" . $current_user_firstname . "'>
<input type='submit' value='APPROVED' formaction='http://telecomsolutions.com/approved.php'>
<input type='submit' value='DRAFT REJECT'>
<textarea name='reject_reason' placeholder='Enter reject reason' id='reject_reason' rows='15' cols='30'>
<input type='submit' value='REJECT' formaction='http://telecomsolutions.com/reject.php'>
</form>
</body>
</html>";
The above one still looks complex and difficult to manage.
You can use concatenation (.)
$message="<html>"
. "<head>"
. "<title>REQUEST FOR TIME SHEET APPROVAL</title>"
. "<style>"
. "</style>"
. "</head>"
. "<body>"
. "<form>"
. "<input type='text' id='current_user_first_name'
name='current_user_first_name'
value='" . $current_user_firstname . "'>"
. "<input type='submit' value='APPROVED' formaction='http://telecomsolutions.com/approved.php'>"
. "<input type='submit' value='DRAFT REJECT'>"
. "<textarea name='reject_reason' placeholder='Enter reject reason' id='reject_reason' rows='15' cols='30'>"
. "<input type='submit' value='REJECT' formaction='http://telecomsolutions.com/reject.php'>"
. "</form>"
. "</body>"
. "</html>";
I am trying to call JavaScript reset() function by using button onclick method. The code is embedded in PHP as follows :
<?php
echo "<form>";
echo "<input type='text' name='keyword'>";
echo "<input type='button' value='Clear' onclick='<script>reset();</script>'>";
echo "</form>";
?>
The clear button is not working.
One solution would be to replace input button line with following:
echo "<input type='button' value='Clear' onclick='javascript:reset()'>";
try this:
<?php
echo "<form>";
echo "<input type='text' name='keyword'>";
echo "<input type='button' value='Clear' onclick='reset()'";
echo "</form>";
This should work - But i would try to get away from putting event handlers inline like this. Perhaps you could use jquery instead.
Below however is a 'Vanilla javascript" solution as you requested...
<?php
echo "
<form>
<input type='text' name='keyword'>
<input type='button' value='Clear' onclick='this.parentNode.reset()' >
</form>
";
?>
You can do this if you want :
<?php
echo "<form>";
echo "<input type='text' name='keyword'>";
echo " <input type='button' value='Clear' onclick='reset();'>";
echo "</form>";
?>
Another way to show HTML code in PHP :
Instead of using echo you can just put any HTML or Javascript code in side this ?> HTML | JAVASCRIPT CODE <?PHP
If you want to put PHP code inside that HTML code you can do the normal procedure which is this :
Example :
<?php
// Here it can be any PHP code
?>
<form>
<input type="hidden" name="<?php echo 'phpinsidehtml';?>"> //This is an example
<input type='text' name='keyword'>
<input type='button' value='Clear' onclick='reset();'>
</form>
<?php
?>
I have a for I=1 to 5 loop with sleep for 5 seconds.
How can I make a menu selection and continue to another page before the while loop is done.
Now when I chose the menu item the selection will take place when the while loop is done. Its about 30 seconds.
I have tried to put the while loop in an Iframe, and load it from another page, but it still first load next page when while loop is done.
From index page
<link rel="icon" href= (./image/favicon.ico)/>
<link rel="stylesheet" href="./db/abcss.css" type="text/css"/>
<script type="text/javascript" src="./db/CSSnav.js"></script>
</HEAD>
<body>
<div id="wrapper">
<?php
include("top.php");
include("IndexMenu.php");
?>
<div id="content75">
<div id="h4"> <br/><b><center>Velkommen til t</center></b>
</div>
<div id="h3"><br/><center> text here. </center><br/><br/>
<iframe src="./eventrul.php" name = "content_iframe"></iframe>
<?php
include("Bund.php")
?>
</body>
</html>
From while loop page
if ($info = mysql_fetch_array($data)){
echo "<div id=\"event\">";
while ($info = mysql_fetch_array($data) and $i < 5){
echo "<script>";
echo "document.getElementById('event').innerHTML = \"\"";
echo "</script>";
echo "<div id=\"event_indhold\">";
if ($info['type']==='Andet'){
$info['type'] = $info['typeandet'];
}
if ($info['emne']==='Andet'){
$info['emne'] = $info['emneandet'];
}
echo "<table><tr><td width = 30% > "." <B>Event nummer: </B>"."</td>"
. "<td colspan = 10>".$info['arrnr'].", Overskrift: ". $info['type']."</td></tr><br/>";
if ($info['arrangoer']!= ""){
echo "<tr><td colspan =10>"." ".$info['arrangoer']."</td> </tr>";
}
ob_flush();
flush();
sleep(4);
$i++;
echo "</div>";
}
echo "<script>";
echo "document.getElementById('event').innerHTML = \"\"";
echo "</script>";
echo "<div id=\"event_indhold\">";
echo '<font size="5px">Klikke her for at se eventlisten ';
echo "</div>";
echo "</div>";
}
You could put a break; when you know you want to exit the loop. It will simply break it.
I'm trying to submit a POST and a GET form with one submit button. I tried using the following php code:
echo "<html>\n<head>\n<title>Params</title>";
echo "<script type='text/javascript'>";
echo "function submitForms(){
document.getElementById('form1').submit();
document.getElementById('form2').submit();
}";
echo "</script>";
echo "</head>";
echo "<body>";
echo "<form action='' method='get' id='form1'>";
echo "<label>First Name </label>";
echo "<input type='text' name='first'><br/>";
echo "<label>Last Name </label>";
echo "<input type='text' name='last'><br/>";
echo "<label>Age </label>";
echo "<input type='text' name='age'><br/>";
echo "<label>Telephone </label>";
echo "<input type='text' name='phone'><br />";
echo "</form>";
echo "<form action='' method='post' id='form2'>";
echo "<label>Username </label>";
echo "<input type='text' name='username'>";
echo "<label>Password </label>";
echo "<input type='password' name='password'>";
echo "</form>";
echo "<input type='submit' value='Send' onclick='submitForms();'>";
echo "</body></html>";
What I get is only the POST params, while the GET request is not loading at all.
How can I fix this?
Thanks in advance.
You should take only one form all fields in that and after getting all input data after submit you can do whatever you want to do..
The way you are doing this is not possible reason being when form is submitted control goes to server to handle http request. hence only one form can be submit at a time. You can't submit two forms at once.. try changing order of form submit and other form will start submitting..
You should use AJAX (jQuery). Something like this should do the trick:
//Onclick for any button you wish to submit the forms
$('#form2 input[name="submit"]').click(function(e) {
e.preventDefault();
var formOne = $("#form1"),
formTwo = $("#form2");
//Post first form
$.post( formOne.attr('action') , formOne.serialize(), function() {
alert('Form one posted!');
});
//Post second form
$.post( formTwo.attr('action') , formTwo.serialize(), function() {
alert('Form two posted!');
});
});
Not tested yet, but this should work. More information for the $.post method can be found here.
My code is fetch data from database (suppose there are 4 records). Only first loop that effected when i changed radio button. Below is my code:
PHP CODE
while($row = mysql_fetch_array($sql)){
echo "<div class='loop'>";
echo "<p><input type='checkbox' name='content_type' value='1' /></p>";
echo "<p><input type='checkbox' name='content_type' value='2' /></p>";
echo "<p><input type='checkbox' name='content_type' value='3' /></p>";
//content_a
echo "<div id='content_a' style='display:none;'>";
echo "<textarea name='text' id='textarea0'><textarea>";
echo "</div>";
//content_b
echo "<div id='content_b' style='display:none;'>";
echo "<textarea name='text' id='textarea1'><textarea>";
echo "</div>";
//content_c
echo "<div id='content_c' style='display:none;'>";
echo "<textarea name='text' id='textarea2'><textarea>";
echo "</div>";
//button
echo "<div class='button'>";
echo "<a class="tweet1" href="#" onclick="return false;">Alert</a>";
echo "</div>";
echo "</div>";
}
Javascript
$('input[name=content_type]').bind('change', function(){
var n = $(this).val();
switch(n)
{
case '1':
$(this).parents('.loop').find('#content_a').show(1000);
$(this).parents('.loop').find('#content_b').hide(1000);
$(this).parents('.loop').find('#content_c').hide(1000);
break;
case '2':
$(this).parents('.loop').find('#content_b').show(1000);
$(this).parents('.loop').find('#content_a').hide(1000);
$(this).parents('.loop').find('#content_c').hide(1000);
break;
case '3':
$(this).parents('.loop').find('#content_c').show(1000);
$(this).parents('.loop').find('#content_a').hide(1000);
$(this).parents('.loop').find('#content_b').hide(1000);
break;
}
});
I want radio button action change according to the loop that fetch from database. My code above, only first loop that effected. How to solve this problem?
that is beacuse id should always be unique...here (in your code ) you have multiple elements with same id id='content_a' (since it is inside a loop) . change this to class and use class selector
try this
html
echo "<div class='content_a' style='display:none;'>";
//---^^^^^ here
jquery
$(this).parents('.loop').find('.content_a').show(1000);\
//-------^-----here
change likewise to all other id selector
and while parents('.loop') works.. i recommend to use closest() for better performance
$(this).closest('.loop').find('.content_a').show(1000);
and yes.. you can reduce your code to two lines if you chnage your html properly..
first change you content to match with the checkbox value..
echo "<div class='content_1' style='display:none;'>"; //here class='content_' + value of checkbox
.....
echo "<div class='content_2' style='display:none;'>";
... //so on
try this
$('input[name=content_type]').bind('change', function(){
var n = $(this).val();
$('div[class^="content_"]').hide(); //hide all div
$(this).closest('.loop').find('.content_' + n).show(1000); //so particular div
});