Jump to content

Defining Anchor Tag Using HTML Form


epseix

Recommended Posts

Bit confused here...

 

Have the following form which allows me to enter a search term, define the table (tbl) from which to search and limit of results, however I also need to define an anchor tag at the end of the url which matches the tbl.

 

eg.

 

        <div class="b2">
          <form action="/admin/home.php" method="GET">
            <div class="row">
              <input name="search" size="19" type="text" value="">
            </div>
            <div class="row">        
              <select name="tbl">
                <option selected>blog</option>
                <option>book_me</option>
                <option>comments</option>
                <option>events</option>
                <option>faq</option>
                <option>links</option>
                <option>workshops</option>
              </select>
            </div>
            <div class="row">        
              <select name="limit">
                <option selected>50</option>
                <option>100</option>
                <option>250</option>
                <option>500</option>
                <option>1000</option>
                <option value="">All</option>
              </select>
            </div>
            <div class="row"><input class="submit" type="submit" value="Go!"></div>
          </form>
        </div>

 

This code will produce:

 

/admin/home.php?search=&tbl=blog&limit=50

 

...wheras I need it to produce...

 

/admin/home.php?search=&tbl=blog&limit=50#blog OR

/admin/home.php?search=&tbl=events&limit=50#events OR

/admin/home.php?search=&tbl=workshops&limit=50#workshops etc.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/255160-defining-anchor-tag-using-html-form/
Share on other sites

I don't really understand why you need to do this? Nevertheless you can simply detect the form submission and inject the value of the select before allowing it to continue:

 

<form action="/admin/home.php" method="GET" name="search">

 

document.search.onsubmit = function()
{
    this.action = this.action.substr(0, this.action.indexOf('#') + 1);
    this.action += '#' + this.tbl.value;
}

 

The added name attribute in the form tag is important.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.