2010-11-16 64 views
0

我有一個形式的代碼....即時創建一個鏈接時,用戶將在一個表單箱

<form id="orderform" method="post" orderform="" name=""> 
    <table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable"> 
    <tbody> 
    <tr> 
     <td>Product Code</td> 
     <td>Meterage</td> 
     <td>Sample Img</td> 
    </tr> 
    <tr class="item"> 
     <td class="prodcode"> 
     <input type="text" id="prodcode" name="prodcode"> 
     </td> 
     <td class="meterage"> 
     <input type="text" id="meterage" name="meterage"> 
     </td> 
     <td class="imgsample"></td> 
    </tr> 
    </tbody> 
    </table> 
</form> 

什麼,我想,當用戶點擊開箱即用的prodcode是它搜索的圖像參考文件夾...的imgsample頭使用便進入了prodCode特定項目下創建一個鏈接...

http://www.mylink.com/images/folder/sub-folder/imageref.jpg

這是一個不可能完成的任務,任何想法?

+0

請注意,當我說,它搜索一個最新的jQuery文件夾,它可能有子文件夾(圖像的類別)和生病只有產品代碼搜索... :( – Andy 2010-11-16 09:12:00

回答

1

我希望這是你所要求的。

$("#prodcode").blur(function() { 
    $.post(
     'yourpage.php', //this page reads the image code and gives you the image location 
     { action: 'searchimage', imgreference: $('#prodcode').val() }, 
     function(data) { 
      //export the link as data    
      $("td.imgsample").html('<img src="'+data+'"/>'); 
     } 
     ); 
}); 
+0

我得到這個錯誤或是yourpage.php一個搜索腳本來找到目錄嗎? – Andy 2010-11-16 09:34:34

+0

是的,您發送代碼的頁面讓我法師的位置。 – Starx 2010-11-16 09:36:12

+0

哇...非常酷!讓我試試這個壞孩子吧。感謝您的幫助! – Andy 2010-11-16 09:36:38

0

綁定到prodcode輸入的模糊事件,
當它模糊了問題的AJAX調用服務器,以獲得正確的網址
,並在回調只是建立鏈接並將其設置爲.imgsample的HTML

+0

這聽起來什麼即時消息後,你知道任何代碼示例,以幫助我把這個地方? – Andy 2010-11-16 09:36:03

0

如果你想有一個鏈接,你需要確保它ISD是得到它最接近的表格單元格,你有,你可以嘗試像

$("#prodcode").bind("blur", function() { 
    var linkStr = "<a href="http://www.mylink.com/images/folder/sub-folder/"+ $("#prodcode").val()+".jpg"; 
    $("#prodcode").closest("td.imgsample").html(linkStr); 
}); 
+0

這很酷,但不是我所追求的,如果我的描述不完全正確,我很抱歉! t搜索文件夾和子文件夾以生成鏈接... – Andy 2010-11-16 09:35:28