Im coding php and i want to use image-button to call function.
$del= "<input type='image' src='delete.png' name='delete_cat' value='{$cat_name}' onclick='delete_exe(this.form,this.name,this.value)' >";
This button is into a submit form
<form method="post" action="caffe_menu_category_post.php">
/form>
My problem is that when js function(delete_exe()) call and execute, then have auto-submit.
I don't want that. Is there any solution or alternative code?
Can i set submit off for my button?
Thanks in advance.
ps in my code i submit form with submit input
input type = "submit" value = "Submit Your Entries">
Use
return false;
in the end of your delete_exe(); function. That will cancel submitting.
Ok. i find the solution. I change my post form
form name="myForm" method="post" action="caffe_menu_category_post.php" onsubmit="return validateForm()">
And use javascripts
var val=true;
function delete_exe(sel,kind,name){
//Set val false to stop submit
val=false;
}
function validateForm(){
if(!val){
//Stop submit
return false;
}
}
So the auto-submit stop.
On the oher hand when click submit button i call js function to set val=true;
i don't know if these is the best solution, but it's work for me!
Related
I'm trying to submit a form after updating the value of a hidden field from a javascript variable.
This is the code:
<form name=form1 id=form1 method=get action=gestionale.php>
...
...
<input type=hidden name=scrolltop id=scrolltop value=''>
<input type=button name=update value=Update onClick=vai('form1');>
</form>
<script>
function vai(formid) {
document.getElementById('scrolltop').value=document.getElementById('offerte').scrollTop;
document.getElementById(formid).submit();
}
</script>
The form submit works correctly but $_GET[scrolltop] after form submission, is empty even if it was filled with javascript. And testing it with alert before submit shows the correct value.
Anyone knows why?
Thanks a lot.
In your script...
The line document.getElementById('scrolltop').value = document.getElementById('offerte').scrollTop;
What exactly do you intend to do with the last bit (('offerte').scrollTop)?
As far as I understand, you want to return a text value, however setting the value to this will not return anything.
You will need to parse the query string ($_GET variable) and assign that to a variable which you will then pass as the value for the hidden field.
If I'm being completely in the dark here, I'm sorry. You should include a bit more of your code or additional information if my answer seems far fetched.
Anyway, I hope this helps!
I found this:
function submit_form(formid) {
var hidden = document.createElement("input");
hidden.type = "hidden";
hidden.name = "theName";
hidden.value = document.getElementById('offerte').scrollTop;
var f = document.getElementById("form2");
f.appendChild(hidden);
f.submit();
}
I submit the form using a javascript function instead of submit button.
Here I can set a hidden filed to a value I need in my action page.
I want to add a sound when the submit button in my form is pressed, but no matter what I do, the sound doesn't finish. It is 1 second long, but the form is submitted under 1 second, so it sounds really bad. This is the code:
Creating the sound:
<script type="text/javascript">
var html5_audiotypes={
"mp3": "audio/mpeg"
}
function createsoundbite(sound){
var html5audio=document.createElement('audio')
if (html5audio.canPlayType){
for (var i=0; i<arguments.length; i++){
var sourceel=document.createElement('source')
sourceel.setAttribute('src', arguments[i])
if (arguments[i].match(/\.(\w+)$/i))
sourceel.setAttribute('type', html5_audiotypes[RegExp.$1])
html5audio.appendChild(sourceel)
}
html5audio.load()
html5audio.playclip=function(){
html5audio.pause()
html5audio.currentTime=0
html5audio.play()
}
return html5audio
}
else{
return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio unfortunately")}}
}
}
var mouseClick=createsoundbite("sounds/cashSound.mp3")
</script>
HTML:
<form method='post' action='save.php'>
<input type='submit' name='apply' value='Play' onclick='mouseClick.playclip()' />
</form>
I tried the setTimeout function but it didn't work! Any suggestions?
Try to return false in playClip function. This may cause, the submit action will not be performed. You can wait for one second and call submit() on form element. You can also send form by AJAX.
Leaving aside the aesthetics, if you really want the sound to finish, then you'll need to delay submission / delay the response or play the sound in a seperate frame, one which is not embedded within the same page as the form.
id doesn't want to put the value in to the document.getElementById("UniLoc").value = val; and it doesn't want to submit the form how to fix this ?
This is how I call the function JS nas some value "asd56"
echo "
<script type="text/javascript">
repostD("'.$JS.'");
</script>";
here is my function inside
<script>
function repostD(val)
{
//document.getElementById("UniLoc").value = val;
document.getElementById('UniLoc').innerHTML = val;
//document.UlRL.UniLoc.value = val;
document.forms["UlRL"].submit();
}
</script>
and here is my form in html
<form name="UlRL" id="UlRL" action="in.php" method="post">
<input type="text" id="UniLoc" name="UniLoc" value="<?php echo $UniLoc;?>" />
Use
document.getElementById('UniLoc').value=val;
If there is nothing else wrong with your full form, it should submit. If you haven't closed your form tag, then close it.
</form>
try doint that in php all instead of in function make an if clause down the code that will execute the action of the posting of the form and at the beggining of the php try this
if($JS!="" )
{
$UniLoc=$JS;
$JS="something that will go throught the other if down at the code";
}
else {
$UniLoc=$_POST["UniLoc"];
}
I cant really tell from your question what is wrong, but looking at your code:
document.getElementById('UniLoc').innerHTML=val;
you are trying to set the value of the input with id 'UniLoc', but you are using the wrong syntax. Instead of .innerHTML, use .value
document.getElementById('UniLoc').value=val;
I'm having a problem with a HTML form (name, e-mail, subject, message), I can't validate the form if it was completed correct or not. I want to call a javascript function when the form is submitted and alert if a field wasn't completed correct.
My problem is with the submit button, because my boss said that I must use he's own php function to insert a submit button. The php function looke like:
function normal_button($text, $width, $param = '', $class = 'button-blue')
{
$content = '<div class="'.$class.'" style="width:'.$width.'px;" '.$param.'>'.$text.'</div>';
return $content;
}
and how I call the function:
echo normal_button('Send it', '100', 'onclick="document.getElementById(\'emailForm\').submit();" ');
I tried to call the js function declaring the onSubmit="return checkForm(this)" in the <form action='email.php' method='post'> HTML form, but I can't "catch" the submit. Also I tried to catch it with jquery, $(document).ready(function() { $('.normal_button').click(function() { }); ); but I can't return false if a field wasn't completed correct.
I must use he's PHP function to insert the submit button, but how can I "catch" the fields, how can I validate them? Any suggestions? Thank you !
First of all, set ID for that form and for sbmit DIV button.
<form action='email.php' method='post' id='mailForm'>
and
echo normal_button('Send it', '100', 'id="mailFormSubmit"');
then do check with jQuery:
$('#mailFormSubmit').click(function(){
// fields check code goes here
....
// if all fields are OK, then submit form
$('#mailForm').submit();
});
This submitenter function is floating around the internet, apparently it is from O'Reilly's. Good job, however, I need it to POST a specific submit value. (Submit button is named submitReport). I have tried
myfield.form.submitReport();
but it doesn't work. I don't really have any ideas about what to do at this point. I am willing to bet that the answer is straightforward but I am stumped, I'd love any suggestions.
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
myfield.form.submit();
return false;
}
else
return true;
}
Here is the submit button I am trying to have it enter for me.
The script must produce 'submitReport', there is a PHP function looking for $_POST['submitReport'], this is because there are a few forms on this page.
<form name= "Insert" onsubmit="return validate(this)" method="post" action="">
<textarea name ="link"></textarea>
<textarea name ="country"></textarea>
<textarea name ="province"></textarea>
<input
type ="submit"
style="visibility:hidden"
name ="submitReport"
value =''
>
</form>
Add a hidden field to the form that is named submitReport.
You only have a problem in the first place because you are using textarea elements where it seems input elements would be more appropriate.
If users recognise the textarea as a textarea, they don't expect pressing enter or return to submit the form so you are breaking the usuability of the page. If you are making the textarea elements look like inupts, then use inputs and no javascript is required to submit the form.