English 中文(简体)
根据案文投入改变形式行动
原标题:Changing form action based on text input

因此,我有一个简单的搜寻形式,并提交纽特。 我想做的是,如果是的话,那么我就希望将输入(频率)发送到倒转.php。 否则,我会派去搜寻。 php。

<script type="text/javascript" language="JavaScript">
function chgact()
   {
if(document.myform.que.indexOf(=) == true) {
   document.myform.action =  /vert.php ;
   }
return true;
}
</script>
    <h1>Keyword search</h1>
    <form name="myform" method="post" action="/search.php"  onSubmit="return chgact()">
      Keywords: <br/>
      <input type="text" name="que" id="que" / >
      <p/>
      Items to display: <br/>
      <select name="i">
        <option value="10">10</option>
        <option value="25">25</option>
        <option value="50">50</option>
      </select>
      <p/>
      <input type="submit" name="submit" value="Search"/>
    </form>

一切帮助都会受到如此贪 gr的赞赏!

最佳回答

更改第4行至<代码>if(文件.myform.que. Value.indexOf(= )! 页: 1

You need to get the value of que, you need to enquote the equals sign (you re searching for the character = ), and the indexOf function returns either -1 if not found or the position of the first occurrence, which is an integer. It does not return a boolean value.

增订的法典如下:

<script type="text/javascript" language="JavaScript">
function chgact()
   {
if(document.myform.que.value.indexOf( = ) != -1) {
   document.myform.action =  /vert.php ;
   }
return true;
}
</script>
    <h1>Keyword search</h1>
    <form name="myform" method="post" action="/search.php"  onSubmit="return chgact()">
      Keywords: <br/>
      <input type="text" name="que" id="que" / >
      <p/>
      Items to display: <br/>
      <select name="i">
        <option value="10">10</option>
        <option value="25">25</option>
        <option value="50">50</option>
      </select>
      <p/>
      <input type="submit" name="submit" value="Search"/>
    </form>
问题回答

I would suggest you perform this action with PHP. If your site visitor has JavaScript turned off, they won t get the benefit of your logic. I suggest you look at strpbrk() function to detect the "=" char.





相关问题
Which non-bold UTF-8 iPhone SDK font can I use here?

Problem: I create a UILabel with this font: label.font = [UIFont systemFontOfSize:15.0f]; Now this system font is bold, but I want to display pretty small text, and the text may also contain very ...

Limiting file upload type

Simple question. Is there a way to only allow txt files upon uploading? I ve looked around and all I find is text/php, which allows PHP. $uploaded_type=="text/php

Extract everything from PDF [closed]

Looking for solution to extract content from a PDF file (using console tool or a library). It will be used on server to produce on-line e-books from uploaded PDF files. Need to extract following ...

Flash & external form fields

Does anybody know if this is possible? I am trying to create a flash movie that will show / preview what I am typing into a field in a normal HTML form. The call to update the flash movie would most ...

Avoiding escape sequence processing in ActionScript?

I need to mimic C# functionality of the @ symbol when it precedes a string. @"C:AFilePath" for example What is the best way to do this? Also there are some sites that will escape larger ...

iPhone: Draw rotated text?

I want to draw some text in a view, rotated 90°. I m pretty new to iPhone development, and poking around the web reveals a number of different solutions. I ve tried a few and usually end up with my ...

Numbering in jQuery

How could I change the text below so that the text within it has a number appended to it. <div class="right">This is some text</div> <div class="right">This is some text</div>...

热门标签