drqvsx1228 2014-09-24 07:25 采纳率: 0%
浏览 35

too long

I'm trying to change my form action in my HTML then submit using javascript.

The conditions are in PHP .

I need help if anyone can assist me.

This is my PHP function :-

<?php
error_reporting(0);

if(isset($_POST['email'])){
    $email=$_POST['email'];
   if(!empty($email)) {
       $chrono = 0;
    } else {
       $chrono = 1;
    }
}
?>

The motive of the PHP is to check null email entry.

Here's the javascript function :-

<script type="text/javascript"> 
    function fireform(val){ 
    // missing codes
      document.forms["demoform"].action=val; 
      document.forms["demoform"].submit(); 
    } 
    // missing codes    
</script>

HTML :-

<form name="demoform" action="">        
<input type ="text" name="name" id="name">             
<input type="hidden" name="buttonpressed" id="buttonpressed"> 
<input type="button" value="submit B" onclick="fireform('b')">

I want to do it in a way , when the user entered an empty email , the PHP will read it as chrono = 0. Then goes to javascript , if the chrono equal to 0 , the action will remain empty.

If the chrono = 1 , the javascript will change the action of the form and submit.

I need help thanks.

  • 写回答

2条回答 默认 最新

  • duanbi8529 2014-09-24 07:35
    关注

    I would recommend checking the email field (for being empty) in javascript, and when you have set the proper action submit the form in javascript.

    Check the field:

    $('#<enter id of field>').val();
    

    Update the action:

    $('form').attr('action', 'Enter your updatet action here');
    

    Submit the form:

    http://api.jquery.com/submit/

    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败